﻿using Apple.BLL.Dto.UserDto;
using Apple.BLL.Manager;
using Apple.Helper;
using Apple.Model.Entity;
using HZY.Framework.DependencyInjection;
using IoTClient;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Result = Apple.Helper.SystemEnums.Result;

namespace Apple.SprayingProcessSystem
{
    public partial class FrmLogin : UILoginForm, ISingletonSelfDependency
    {
        private readonly UserManager _userManager;

        public FrmLogin(UserManager userManager)
        {
            InitializeComponent();
            this._userManager = userManager;
        }

        private async void FrmLogin_ButtonLoginClick(object sender, EventArgs e)
        {
            BaseResult<UserEntity> res = await _userManager.LoginAsync(new UserLoginDto
            {
                UserName = this.UserName,
                UserPassword = this.Password
            });

            if (res.Status == Result.Success)
            {
                IsLogin = true;
                this.ShowSuccessTip("登录成功!");
                Close();
            }
            else
            {
                this.ShowErrorTip(res.Msg);
            }
        }

        #region 窗体切换卡顿处理
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams paras = base.CreateParams;
                paras.ExStyle |= 0x02000000;
                return paras;
            }
        }
        #endregion
    }
}
